import { createSlice } from "@reduxjs/toolkit"

const counterStore = createSlice({
  name: 'user',
  // 初始化state
  initialState: {
    token: "",
    userId: 0,
  },
  // 修改状态的方法 同步方法 支持直接修改
  reducers: {
    setToken (state, action) {
      console.log(action.payload)
      state.token = action.payload
    },
    setUserId (state, action) {
      console.log(action.payload)
      state.userId = action.payload
    }
  }
})

// 解构出来actionCreater函数
const { setToken,setUserId } = counterStore.actions
// 获取reducer
const reducer = counterStore.reducer

// 以按需导出的方式导出actionCreater
export { setToken,setUserId }
// 以默认导出的方式导出reducer
export default reducer